#ifndef AVCODEC_SAMPLE_MULTI_SURFACE2_H
#define AVCODEC_SAMPLE_MULTI_SURFACE2_H

#include <bits/alltypes.h>
#include <mutex>
#include <memory>
#include <atomic>
#include <thread>
#include <unistd.h>
#include "capbilities/base/video_sample_base.h"
#include "video_decoder.h"
#include "capbilities/data_producer/demuxer/demuxer.h"
#include "sample_info.h"
#include "plugin_manager.h"

class MultiSurface_2 : public VideoSampleBase {
public:
    static MultiSurface_2 &GetInstance() {
        static MultiSurface_2 multiSurface_;
        return multiSurface_;
    }

    int32_t Create(SampleInfo &sampleInfo) override;
    int32_t Start() override;
    int32_t Stop();
    int32_t Pause();
    int32_t Play();
    int32_t VideoSeek(int64_t currentTime);
    int32_t Loop(bool loopFlag);
    int32_t SetSurface(const std::string id);

    bool isVertical = false;
    std::atomic<bool> isStarted{false};
    bool autoSwitchSurface = false;

private:
    void DecInputThread();
    void DecOutputThread();
    void Release() override;

    std::unique_ptr<VideoDecoder> videoDecoder_ = nullptr;

    std::mutex mutex_;
    std::atomic<bool> isLoop{false};
    std::atomic<bool> isPause{false};
    std::unique_ptr<std::thread> decInputThread_ = nullptr;
    std::unique_ptr<std::thread> decOutputThread_ = nullptr;
    std::unique_ptr<std::thread> releaseThread_ = nullptr;
    SampleInfo sampleInfo_;
    static constexpr int64_t MILLISECONDS = 1000;
    static constexpr int64_t MICROSECOND = 1000000;

    bool switchSurfaceFlag = false;

private:
    MultiSurface_2(){};
    ~MultiSurface_2();
};

#endif // AVCODEC_SAMPLE_MULTI_SURFACE2_H
